package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.WeekResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Huiyuan;
import com.ruoyi.system.service.IHuiyuanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-28
 */
@RestController
@RequestMapping("/system/huiyuan")
public class HuiyuanController extends BaseController
{
    @Autowired
    private IHuiyuanService huiyuanService;

    /**
     * 查询会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:huiyuan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Huiyuan huiyuan)
    {
        startPage();
        List<Huiyuan> list = huiyuanService.selectHuiyuanList(huiyuan);
        return getDataTable(list);
    }

    /**
     * 导出会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:huiyuan:export')")
    @Log(title = "会员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Huiyuan huiyuan)
    {
        List<Huiyuan> list = huiyuanService.selectHuiyuanList(huiyuan);
        ExcelUtil<Huiyuan> util = new ExcelUtil<Huiyuan>(Huiyuan.class);
        util.exportExcel(response, list, "会员信息数据");
    }

    /**
     * 获取会员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:huiyuan:query')")
    @GetMapping(value = "/{huiyuanId}")
    public AjaxResult getInfo(@PathVariable("huiyuanId") Integer huiyuanId)
    {
        return success(huiyuanService.selectHuiyuanByHuiyuanId(huiyuanId));
    }

    /**
     * 新增会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:huiyuan:add')")
    @Log(title = "会员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Huiyuan huiyuan)
    {
        return toAjax(huiyuanService.insertHuiyuan(huiyuan));
    }

    /**
     * 修改会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:huiyuan:edit')")
    @Log(title = "会员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Huiyuan huiyuan)
    {
        return toAjax(huiyuanService.updateHuiyuan(huiyuan));
    }

    /**
     * 删除会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:huiyuan:remove')")
    @Log(title = "会员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{huiyuanIds}")
    public AjaxResult remove(@PathVariable Integer[] huiyuanIds)
    {
        return toAjax(huiyuanService.deleteHuiyuanByHuiyuanIds(huiyuanIds));
    }

    /**
     * 查询今日注册用户数
     */
    @GetMapping("/selectTodayRegisterCount")
    public int selectTodayRegisterCount(){
        return huiyuanService.selectTodayRegisterCount();
    };

    /**
     * 查询昨天注册用户数
     */
    @GetMapping("/selectYesterdayRegisterCount")
    public int selectYesterdayRegisterCount(){
        return huiyuanService.selectYesterdayRegisterCount();
    };

    /**
     * 查询本周注册用户数
     */
    @GetMapping("/selectWeekRegisterCount")
    public List<WeekResult> selectWeekRegisterCount(){
        return huiyuanService.selectWeekRegisterCount();
    };

    /**
     * 查询本周注册用户数
     */
    @GetMapping("/selectLastWeekRegisterCount")
    public List<WeekResult> selectLastWeekRegisterCount(){
        return huiyuanService.selectLastWeekRegisterCount();
    };
}
